Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
PUT 404 (NOT FOUND) and SyntaxError: Unexpected token < in JSON at position 0

[PUT 404 (NotFound) ][1] [1]: https://i.stack.imgur.com/ugZng.png

Client-side code

const confirmDeliver = (event) => {
const newQuantity = inventory.quantity - 1;
const updateQuantity = { newQuantity };
const url = `http://localhost:5000/inventory/${inventoryId}`;
fetch(url, {
  method: "PUT",
  headers: {
    "content-type": "application/json",
  },
  body: JSON.stringify(updateQuantity),
})
  .then((response) => response.json())
  .then((data) => console.log(data)); };
  

Server-side code

   app.put("inventory/:id", async (req, res) => {
  const id = req.params.id;
  const updatedQuantity = req.body;
  const filter = { _id: ObjectId(id) };
  const options = { upsert: true };
  const updatedDoc = {
    $set: {
      quantity: updatedQuantity.quantity,
    },
  };
  const result = await inventoryCollection.updateOne(
    filter,
    options,
    updatedDoc
  );
  res.send(result);
});

Can anyone tell me why I am getting this error? How can I solve this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

‘Unexpected token <‘ means the response returned is not a valid json. This error may be from a 404 error html page responded from backend.

The request method PUT is different from request methods GET, POST. Make sure the backend has a PUT request method with an appropriate endpoint ‘ http://localhost:5000/inventory/your-inventory-id’.

To fast test a SUCCESS connection to backend, simply return an empty {} json response.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda